package com.ljn.service.imp;

import com.ljn.core.dto.Project;
import com.ljn.core.dto.Relation;
import com.ljn.core.dto.common.utils.UUIDUtils;
import com.ljn.mapper.ProjectMapper;
import com.ljn.mapper.RelationMapper;
import com.ljn.service.ProService;
import org.springframework.transaction.annotation.Transactional;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * Created by liujunnan on 2017/11/15.
 */
@Named
public class ProServiceImpl implements ProService {

    @Inject
    ProjectMapper projectMapper;

    @Inject
    RelationMapper relationMapper;

    @Override
    public Long addPro(Project project) {
        project.setId(UUIDUtils.get32UUIDAsLowerCase());
        project.setStatus(false);
        return this.projectMapper.insertProject(project);
    }

    @Override
    @Transactional
    public Long revPro(Relation relation, String proId) {
        if(proId != null)
        {
            relation.setId(UUIDUtils.get32UUIDAsLowerCase());
            Long flag= relationMapper.insert(relation);
            boolean status = true;
            projectMapper.updateProStatus(proId, status);
            return flag;
        }
        else return null;
    }

    @Override
    public boolean changeProInfo(Project project) {
        return this.projectMapper.updateByPrimaryKeySelective(project) > 0 ? true:false;
    }
}
